<?php
$config=array(
        'user_vali'=> array(
            array(
                'field'=>'user_account',
                'label'=>'用户名',
                'rules'=>'required|min_length[5]|max_length[16]|alpha_dash|unique[user.user_account]',
                 'errors'=>array(
                                'required'=>'用户名不能为空',
                                'min_length'=>'用户名不能小于5个字符',
                                'max_length'=>'用户名不能多于16个字符',
                                'alpha_dash'=>'用户名只能以数字字符下划线组成',
                            ),
                ),
                 array(
                'field'=>'user_pass',
                'label'=>'密码',
                'rules'=>'required|min_length[5]|max_length[16]',
                 'errors'=>array(
                                'required'=>'密码不能为空',
                                'min_length'=>'密码不能小于5个字符',
                                'max_length'=>'密码不能多于16个字符',
                            ),
                ),
                 array(
                'field'=>'passconf',
                'label'=>'密码确认',
                'rules'=>'required|matches[user_pass]',
                'errors'=>array(
                            'required'=>'密码确认不能为空',
                            'matches'=>'密码填写不一致',
                        ),
                ),
                 array(
                'field'=>'user_name',
                'label'=>'真实名称',
                'rules'=>'required|min_length[2]|max_length[16]',
                'errors'=>array(
                                'required'=>'真实名称不能为空',
                                'min_length'=>'真实名称不能小于2个字符',
                                'max_length'=>'真实名称不能多于16个字符',
                                )
                ),
        ),
        'edituser_vali'=> array(
            array(
                'field'=>'user_account',
                'label'=>'用户名',
                'rules'=>'required|min_length[5]|max_length[16]|alpha_dash|_unique[user.user_account]',
                 'errors'=>array(
                                'required'=>'用户名不能为空',
                                'min_length'=>'用户名不能小于5个字符',
                                'max_length'=>'用户名不能多于16个字符',
                                'alpha_dash'=>'用户名只能以数字字符下划线组成',
                            ),
                ),
                 array(
                'field'=>'user_pass',
                'label'=>'密码',
                'rules'=>'required|min_length[5]|max_length[16]',
                 'errors'=>array(
                                'required'=>'密码不能为空',
                                'min_length'=>'密码不能小于5个字符',
                                'max_length'=>'密码不能多于16个字符',
                            ),
                ),
                 array(
                'field'=>'passconf',
                'label'=>'密码确认',
                'rules'=>'required|matches[user_pass]',
                'errors'=>array(
                            'required'=>'密码确认不能为空',
                            'matches'=>'密码填写不一致',
                        ),
                ),
                 array(
                'field'=>'user_name',
                'label'=>'真实名称',
                'rules'=>'required|min_length[2]|max_length[16]',
                'errors'=>array(
                                'required'=>'真实名称不能为空',
                                'min_length'=>'真实名称不能小于2个字符',
                                'max_length'=>'真实名称不能多于16个字符',
                                )
                ),
        ),

         'lgoin_user_vali'=> array(
            array(
                'field'=>'user_account',
                'label'=>'用户名',
                'rules'=>'required',
                 'errors'=>array(
                                'required'=>'用户名不能为空',
                                ),
                ),
                 array(
                'field'=>'user_pass',
                'label'=>'密码',
                'rules'=>'required',
                 'errors'=>array(
                                'required'=>'密码不能为空',
                                ),
                ),
        ),
        'config_vali'=>array(
            array(
              'field'=>'title',
              'label'=>'网站标题',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'%s不能为空',
                               ),
            ),
            array(
                'field'=>'sitelogo',
                'label'=>'网站Logo',
                'rules'=>'required',
                'errors'=>array(
                                'required'=>'%s不能为空',
                               ),
                 ),
                 array(
                'field'=>'keyword',
                'label'=>'网站关键字',
                'rules'=>'required',
                'errors'=>array(
                                'required'=>'%s不能为空',
                               ),
                 ),
                array(
                'field'=>'description',
                'label'=>'网站描述',
                'rules'=>'required',
                'errors'=>array(
                                'required'=>'%s不能为空',
                               ),
                 ),
        ),

         'video_vali'=>array(
            array(
              'field'=>'client_id',
              'label'=>'client_id',
              'rules'=>'required|min_length[16]|max_length[16]',
              'errors'=>array(
                                'required'=>'%s不能为空',
                                 'min_length'=>'%s不能小于16个字符',
                                'max_length'=>'%s不能多于16个字符',
                               ),
            ),
            array(
                'field'=>'client_secret',
                'label'=>'client_secretLogo',
                'rules'=>'required|min_length[32]|max_length[32]',
                'errors'=>array(
                                'required'=>'%s不能为空',
                                 'min_length'=>'%s不能小于32个字符',
                                'max_length'=>'%s不能多于32个字符',
                               ),
                 ),
                 array(
                'field'=>'refresh_token',
                'label'=>'refresh_token',
                'rules'=>'required|min_length[32]|max_length[32]',
                'errors'=>array(
                                'required'=>'%s不能为空',
                                 'min_length'=>'%s不能小于32个字符',
                                'max_length'=>'%s不能多于32个字符',
                               ),
                 )
        ),
         'video_list_vali'=>array(
            array(
              'field'=>'video_id',
              'label'=>'视频id',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'视频必须上传',
                               ),
            ),
        ),
         'about_vali'=>array(
            array(
              'field'=>'title',
              'label'=>'标题',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'标题必须填写',
                               ),
            ),
        ),
         'culture_vali'=>array(
            array(
              'field'=>'ctitle',
              'label'=>'标题',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'标题必须填写',
                               ),
            ),
        ),
         'visionaries_vali'=>array(
            array(
              'field'=>'vtitle',
              'label'=>'标题',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'标题必须填写',
                               ),
            ),
        ),
        'teacher_vali'=>array(
            array(
              'field'=>'name',
              'label'=>'姓名',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'姓名必须填写',
                               ),
            ),
            array(
              'field'=>'weight',
              'label'=>'权重',
              'rules'=>'required|greater_than[-1]|integer',
              'errors'=>array(
                                'required'=>'权重必须填写',
                                'greater_than'=>'权重必须是数字并且大于等0',
                                'integer'=>'权重必须为数字'
                               ),
            ),
        ),
        'event_vali'=>array(
            array(
              'field'=>'title',
              'label'=>'标题',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'标题必须填写',
                               ),
            ),
            array(
              'field'=>'weight',
              'label'=>'权重',
              'rules'=>'required|greater_than[-1]|integer',
              'errors'=>array(
                                'required'=>'权重必须填写',
                                'greater_than'=>'权重必须是数字并且大于等0',
                                'integer'=>'权重必须为数字'
                               ),
            ),
             array(
                'field'=>'description',
                'label'=>'描述',
                'rules'=>'max_length[80]',
                'errors'=>array(
                                'max_length'=>'%s不能多于80个字符',
                               ),
                 )
        ),
         'new_vali'=>array(
            array(
              'field'=>'title',
              'label'=>'标题',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'标题必须填写',
                               ),
            ),
            array(
              'field'=>'weight',
              'label'=>'权重',
              'rules'=>'required|greater_than[-1]|integer',
              'errors'=>array(
                                'required'=>'权重必须填写',
                                'greater_than'=>'权重必须是数字并且大于等0',
                                'integer'=>'权重必须为数字'
                               ),
            ),
             array(
                'field'=>'description',
                'label'=>'描述',
                'rules'=>'max_length[80]',
                'errors'=>array(
                                'max_length'=>'%s不能多于80个字符',
                               ),
                 )
        ),
        'down_vali'=>array(
            array(
              'field'=>'title',
              'label'=>'标题',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'标题必须填写',
                               ),
            ),
            array(
              'field'=>'weight',
              'label'=>'权重',
              'rules'=>'required|greater_than[-1]|integer',
              'errors'=>array(
                                'required'=>'权重必须填写',
                                'greater_than'=>'权重必须是数字并且大于等0',
                                'integer'=>'权重必须为数字'
                               ),
            ),
             array(
                'field'=>'imgurl',
                'label'=>'图片',
                'rules'=>'required',
                'errors'=>array(
                                'required'=>'图片必须上传',
                               ),
                 ),
                 array(
                'field'=>'downurl',
                'label'=>'图片',
                'rules'=>'required',
                'errors'=>array(
                                'required'=>'图片必须上传',
                               ),
                 )
        ),
         'project_vali'=>array(
            array(
              'field'=>'title',
              'label'=>'标题',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'标题必须填写',
                               ),
            ),
        ),
         'multimedia_vali'=>array(
            array(
              'field'=>'mtitle',
              'label'=>'标题',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'标题必须填写',
                               ),
            ),
        ),

         'didactics_vali'=>array(
            array(
              'field'=>'title',
              'label'=>'标题',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'标题必须填写',
                               ),
            ),
            array(
              'field'=>'weight',
              'label'=>'权重',
              'rules'=>'required|greater_than[-1]|integer',
              'errors'=>array(
                                'required'=>'权重必须填写',
                                'greater_than'=>'权重必须是数字并且大于等0',
                                'integer'=>'权重必须为数字'
                               ),
            ),
             array(
                'field'=>'description',
                'label'=>'描述',
                'rules'=>'max_length[47]',
                'errors'=>array(
                                'max_length'=>'%s不能多于47个字符',
                               ),
                 )
        ),
         'material_vali'=>array(
            array(
              'field'=>'title',
              'label'=>'材质',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'材质必须填写',
                               ),
            ),
        ),
         'style_vali'=>array(
            array(
              'field'=>'title',
              'label'=>'款式',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'款式必须填写',
                               ),
            ),
        ),
         'size_vali'=>array(
            array(
              'field'=>'title',
              'label'=>'尺码',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'尺码必须填写',
                               ),
            ),
        ),
         'color_vali'=>array(
            array(
              'field'=>'title',
              'label'=>'颜色描述',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'颜色描述必须填写',
                               ),
            ),
            array(
              'field'=>'colorkey',
              'label'=>'色值',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'颜色色值必须填写或者选择',
                               ),
            ),
        ),
         'goods_vali'=>array(
            array(
              'field'=>'title',
              'label'=>'商品名称',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'商品名称必须填写',
                               ),
            ),
            array(
              'field'=>'shop_price',
              'label'=>'商城价格',
              'rules'=>'required|regex_match[/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)/]',
              'errors'=>array(
                                'required'=>'商城价格必须填写',
                                'regex_match'=>'价格格式不正确'
                               ),
            ),
             array(
              'field'=>'market_price',
              'label'=>'市场价格',
              'rules'=>'required|regex_match[/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)/]',
              'errors'=>array(
                                'required'=>'市场价格必须填写',
                                'regex_match'=>'价格格式不正确'
                               ),
            ),
             array(
              'field'=>'imgurl',
              'label'=>'商品图片',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'商品图片必须上传',
                               ),
            ),
             array(
              'field'=>'weight',
              'label'=>'权重',
              'rules'=>'required|greater_than[-1]|integer',
              'errors'=>array(
                                'required'=>'权重必须填写',
                                'greater_than'=>'权重必须是数字并且大于等0',
                                'integer'=>'权重必须为数字'
                               ),
            ),
             array(
              'field'=>'discount',
              'label'=>'折扣',
              'rules'=>'required|greater_than[-1]|numeric|less_than[10]',
              'errors'=>array(
                                'required'=>'折扣必须填写',
                                'greater_than'=>'折扣必须是数字并且大于等0',
                                'integer'=>'折扣必须为数字',
                                'less_than'=>"折扣最大值为9.9"
                               ),
            ),
        ),
         'contact_vali'=>array(
            //array(
            //  'field'=>'title',
            //  'label'=>'标题',
            //  'rules'=>'required',
            //  'errors'=>array(
            //                    'required'=>'标题必须填写',
            //                   ),
            //),
        ),
         'question_vali'=>array(
            array(
              'field'=>'q_contents',
              'label'=>'问题描述',
              'rules'=>'required|max_length[500]',
              'errors'=>array(
                                'required'=>'问题描述必须填写',
                                'max_length'=>'问题描述最长为500字符'
                               ),
            ),
             array(
              'field'=>'a_contents',
              'label'=>'问题答复',
              'rules'=>'required|max_length[500]',
              'errors'=>array(
                                'required'=>'问题答复必须填写',
                                'max_length'=>'问题答复最长为500字符'
                               ),
            ),
            array(
              'field'=>'weight',
              'label'=>'权重',
              'rules'=>'required|greater_than[-1]|integer',
              'errors'=>array(
                                'required'=>'权重必须填写',
                                'greater_than'=>'权重必须是数字并且大于等0',
                                'integer'=>'权重必须为数字'
                               ),
            ),
        ),
        'goodsimg_vali'=>array(
            array(
              'field'=>'imgurl',
              'label'=>'商品图片',
              'rules'=>'required',
              'errors'=>array(
                                'required'=>'商品图片必须上传',
                               ),
            ),
        ),

        //前端验证
         'account_vali'=> array(
            array(
                'field'=>'account',
                'label'=>'用户名',
                'rules'=>'required|min_length[5]|max_length[16]|alpha_dash|unique[customer.account]',
                 'errors'=>array(
                                'required'=>'用户名不能为空',
                                'min_length'=>'用户名不能小于5个字符',
                                'max_length'=>'用户名不能多于16个字符',
                                'alpha_dash'=>'用户名只能以数字字符下划线组成',
                            ),
                ),
                 array(
                'field'=>'pass',
                'label'=>'密码',
                'rules'=>'required|min_length[5]|max_length[16]',
                 'errors'=>array(
                                'required'=>'密码不能为空',
                                'min_length'=>'密码不能小于5个字符',
                                'max_length'=>'密码不能多于16个字符',
                            ),
                ),
                 array(
                'field'=>'passconf',
                'label'=>'密码确认',
                'rules'=>'required|matches[pass]',
                'errors'=>array(
                            'required'=>'密码确认不能为空',
                            'matches'=>'密码填写不一致',
                        ),
                ),
                 array(
                'field'=>'email',
                'label'=>'邮箱',
                'rules'=>'required|checkemaile',
                'errors'=>array(
                                'required'=>'邮箱不能为空',

                                )
                ),
                 array(
                'field'=>'phone',
                'label'=>'手机',
                'rules'=>'required|checkphone',
                'errors'=>array(
                                'required'=>'手机不能为空',

                                )
                ),
        ),
        'account_u_d_vali'=> array(
            array(
                'field'=>'account',
                'label'=>'用户名',
                'rules'=>'required|min_length[5]|max_length[16]|alpha_dash|_unique[customer.account.customer_id]',
                 'errors'=>array(
                                'required'=>'用户名不能为空',
                                'min_length'=>'用户名不能小于5个字符',
                                'max_length'=>'用户名不能多于16个字符',
                                'alpha_dash'=>'用户名只能以数字字符下划线组成',
                            ),
                ),

                 array(
                'field'=>'email',
                'label'=>'邮箱',
                'rules'=>'required|checkemaile',
                'errors'=>array(
                                'required'=>'邮箱不能为空',

                                )
                ),
                 array(
                'field'=>'phone',
                'label'=>'手机',
                'rules'=>'required|checkphone',
                'errors'=>array(
                                'required'=>'手机不能为空',

                                )
                ),
        ),
         'account_u_p_vali'=> array(
                 array(
                'field'=>'pass',
                'label'=>'密码',
                'rules'=>'required|min_length[5]|max_length[16]',
                 'errors'=>array(
                                'required'=>'密码不能为空',
                                'min_length'=>'密码不能小于5个字符',
                                'max_length'=>'密码不能多于16个字符',
                                 ),
                ),
                 array(
                'field'=>'passconf',
                'label'=>'密码确认',
                'rules'=>'required|matches[pass]',
                'errors'=>array(
                                'required'=>'密码确认不能为空',
                                'matches'=>'密码填写不一致',
                               ),
                ),
        ),
        //customer_add

         'customer_add_vali'=> array(
                  array(
                'field'=>'c_name',
                'label'=>'姓名',
                'rules'=>'required|min_length[2]|max_length[16]',
                 'errors'=>array(
                                'required'=>'姓名不能为空',
                                'min_length'=>'姓名不能小于2个字符',
                                'max_length'=>'姓名不能多于16个字符',

                            ),
                ),
                 array(
                'field'=>'detailed_add',
                'label'=>'详细地址',
                'rules'=>'required',
                'errors'=>array(
                                'required'=>'详细地址不能为空',
                               ),
                ),
                 array(
                'field'=>'phone',
                'label'=>'手机',
                'rules'=>'required|checkphone',
                'errors'=>array(
                                'required'=>'手机不能为空',

                                )
                ),
        ),
    );
function unique($value, $params) {
    $CI =& get_instance();
    $CI->load->database();
    $CI->form_validation->set_message('unique',
'%s'.$value.'已经被注册');
    list($table, $field) = explode(".", $params, 2);
    $query = $CI->db->select($field)->from($table)
    ->where($field, $value)->limit(1)->get();
    if ($query->row()) {
        return false;
    } else {
        return true;
    }
}

function _unique($value, $params) {
    $CI =& get_instance();
    $CI->load->database();
    $CI->form_validation->set_message('_unique',
'%s'.$value.'已经被注册');
    list($table, $field,$_field) = explode(".", $params, 3);
    $cid= $CI->input->post("$_field");
    //p($cid);
    $sql="select * from $table where $field='".$value."' and $_field<>$cid";

    $res = $CI->db->query($sql)->row();
    if (!empty($res)) {
        return false;
    } else {
        return true;
    }
}

function checkphone($val)
{
    $CI =& get_instance();
    $CI->load->database();
    $CI->form_validation->set_message('checkphone',
'请填写正确的手机号码');
    $reg='/^13[0-9]{1}[0-9]{8}$|15[012356789]{1}[0-9]{8}$|18[012356789]{1}[0-9]{8}$|14[57]{1}[0-9]$/';
    if(preg_match($reg,$val))
    {
        return true;
    }else{

        return false;
    }
}
function checkptel($val)
{
    $CI =& get_instance();
    $CI->load->database();
    $CI->form_validation->set_message('checkptel',
'请填写正确的手机号码');
    $reg='/^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/';
    if(preg_match($reg,$val))
    {
        return true;
    }else{

        return false;
    }
}
function checkemaile($val)
{
    $CI =& get_instance();
    $CI->load->database();
    $CI->form_validation->set_message('checkemaile',
'请填写正确的邮箱地址');
    $reg='/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/';
    if(preg_match($reg,$val))
    {
        return true;
    }else{

        return false;
    }
}
?>